package com.yeshen.pmtea.ui;

import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.TextView;

import com.yeshen.pmtea.R;
import com.yeshen.pmtea.adapters.MyFragmentPagerAdapter;
import com.yeshen.pmtea.fragments.FiveFragment;
import com.yeshen.pmtea.fragments.FourFragment;
import com.yeshen.pmtea.fragments.FristFragment;
import com.yeshen.pmtea.fragments.ThreeFragment;
import com.yeshen.pmtea.fragments.TwoFragment;

import java.util.ArrayList;
import java.util.List;

import static com.yeshen.pmtea.R.id.tv1;
/**
 * 内存 RAM
 *磁盘(外置SD卡,data/data/包名)
 *网络缓存(本应用对应的服务器-->超级计算机)
 * */
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
    private TextView fristView,twoView,threeView,fourView,fiveView;
    private List<TextView> heads;
    private TextView tv11,tv22,tv33,tv44,tv55;
    private List<TextView> lines;
    private ViewPager mViewPager;
    private List<Fragment> mFragments;

    private int qqposition=0;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        getSupportActionBar().hide();
       // Log.d("flag", "---------------onCreate: ");
        initView();
        initData();

    }

    private void initData() {

        mFragments =new ArrayList<>();
        mFragments.add(new FristFragment());
       // Log.d("flag", "---------------initData: " +"dao l ma");
        mFragments.add(new TwoFragment());
        mFragments.add(new ThreeFragment());
        mFragments.add(new FourFragment());
        mFragments.add(new FiveFragment());
        mViewPager.setAdapter(new MyFragmentPagerAdapter(getSupportFragmentManager(),mFragments));
        //监听
        mViewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {
                lines.get(position).setBackgroundColor(Color.GREEN);
                lines.get(qqposition).setBackgroundColor(Color.WHITE);
                heads.get(position).setTextColor(Color.GREEN);
                heads.get(qqposition).setTextColor(Color.BLACK);
                qqposition=position;
            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });

    }

    private void initView() {
        fristView= (TextView) findViewById(tv1);
        twoView= (TextView) findViewById(R.id.tv2);
        threeView= (TextView) findViewById(R.id.tv3);
        fourView= (TextView) findViewById(R.id.tv4);
        fiveView= (TextView) findViewById(R.id.tv5);
        heads=new ArrayList<>();
        heads.add(fristView);
        heads.add(twoView);
        heads.add(threeView);
        heads.add(fourView);
        heads.add(fiveView);
        //条目点击监听
        fristView.setOnClickListener(this);
        twoView.setOnClickListener(this);
        threeView.setOnClickListener(this);
        fourView.setOnClickListener(this);
        fiveView.setOnClickListener(this);

        tv11= (TextView) findViewById(R.id.tv11);
        tv22= (TextView) findViewById(R.id.tv12);
        tv33= (TextView) findViewById(R.id.tv13);
        tv44= (TextView) findViewById(R.id.tv14);
        tv55= (TextView) findViewById(R.id.tv15);
        lines=new ArrayList<>();
        lines.add(tv11);
        lines.add(tv22);
        lines.add(tv33);
        lines.add(tv44);
        lines.add(tv55);

        mViewPager = (ViewPager) findViewById(R.id.viewPager);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.tv1:

                mViewPager.setCurrentItem(0,true);
                break;
            case R.id.tv2:
                mViewPager.setCurrentItem(1,true);
                break;
            case R.id.tv3:
                mViewPager.setCurrentItem(2,true);
                break;
            case R.id.tv4:
                mViewPager.setCurrentItem(3,true);
                break;
            case R.id.tv5:
                mViewPager.setCurrentItem(4,true);
                break;
            case R.id.wodeshoucang:
                Intent intent =new Intent(MainActivity.this,CollectActivity.class);
                this.startActivity(intent);
                Log.d("aflag", "---------------onClick: ");
                break;
        }
    }
}
